//
//  ForgetView.m
//  JackDeve
//
//  Created by apple on 17/5/10.
//  Copyright © 2017年 wkq. All rights reserved.
//

#import "ForgetView.h"

@implementation ForgetView

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
       
        self.backgroundColor=[UIColor colorWithRed:244/255.0 green:244/255.0 blue:244/255.0 alpha:1];
        
        [self addSubview:self.backView];
        [self addSubview:self.backView2];
        [self addSubview:self.backView3];
        [self addSubview:self.sureBtn];
        [_backView addSubview:self.typeLbl];
        [_backView addSubview:self.pwTf];
        [_backView2 addSubview:self.typeLbl2];
        [_backView2 addSubview:self.pwTf2];
        [_backView3 addSubview:self.typeLbl3];
        [_backView3 addSubview:self.pwTf3];
        [self addSubview:self.lable];
        [self layoutViews];
    }
    return self;
}
//旧密码
-(UIView *)backView{
    
    if (_backView==nil) {
        
        _backView                   = [[UIView alloc] init];
        _backView.layer.borderWidth = 1;
        _backView.layer.borderColor = [UIColor colorWithWhite:0.581 alpha:1.000].CGColor;
    }
    return _backView;
    
}
-(UILabel *)typeLbl{
    if (_typeLbl==nil) {
        _typeLbl                    = [[UILabel alloc] init];
        _typeLbl.text               = @"旧密码:";
        _typeLbl.textColor          = [UIColor colorWithRed:(57/255.0) green:(57/255.0) blue:(57/255.0) alpha:1];
    }
    return _typeLbl;
}
-(UITextField *)pwTf{
    if (_pwTf==nil) {
        _pwTf                       = [[UITextField alloc] init];
        _pwTf.tag                   = 1;
        _pwTf.secureTextEntry       = YES;
        _pwTf.delegate              = self;
        _pwTf.clearButtonMode       = UITextFieldViewModeAlways;
        [_pwTf addTarget:self action:@selector(textFieldChange:) forControlEvents:UIControlEventEditingChanged];
    }
    return _pwTf;
}
//新密码
-(UIView *)backView2{
    if (_backView2==nil) {
        _backView2                   = [[UIView alloc] init];
        _backView2.layer.borderWidth = 1;
        _backView2.layer.borderColor = [UIColor colorWithWhite:0.581 alpha:1.000].CGColor;
    }
    return _backView2;
    
}
-(UILabel *)typeLbl2{
    if (_typeLbl2==nil) {
        _typeLbl2                    = [[UILabel alloc] init];
        _typeLbl2.text               = @"新密码:";
        _typeLbl2.textColor          = [UIColor colorWithRed:(57/255.0) green:(57/255.0) blue:(57/255.0) alpha:1];
    }
    return _typeLbl2;
}
-(UITextField *)pwTf2{
    if (_pwTf2==nil) {
        _pwTf2                       = [[UITextField alloc] init];
        _pwTf2.tag                   = 2;
        _pwTf2.secureTextEntry       = YES;
        _pwTf2.delegate              = self;
        _pwTf2.clearButtonMode       = UITextFieldViewModeAlways;
        [_pwTf2 addTarget:self action:@selector(textFieldChange:) forControlEvents:UIControlEventEditingChanged];
    }
    return _pwTf2;
    
}
/** 确认新密码*/
-(UIView *)backView3{
    if (_backView3==nil) {
        _backView3                   = [[UIView alloc] init];
        _backView3.layer.borderWidth = 1;
        _backView3.layer.borderColor = [UIColor colorWithWhite:0.581 alpha:1.000].CGColor;
    }
    return _backView3;
}
-(UILabel *)typeLbl3{
    if (_typeLbl3==nil) {
        _typeLbl3                    = [[UILabel alloc] init];
        _typeLbl3.text               = @"确认新密码:";
        _typeLbl3.textColor          = [UIColor colorWithRed:(57/255.0) green:(57/255.0) blue:(57/255.0) alpha:1];
    }
    return _typeLbl3;
}
-(UITextField *)pwTf3{
    if (_pwTf3==nil) {
        _pwTf3                       = [[UITextField alloc] init];
        _pwTf3.tag                   = 3;
        _pwTf3.secureTextEntry       = YES;
        _pwTf3.delegate              = self;
        _pwTf3.clearButtonMode       = UITextFieldViewModeAlways;
        [_pwTf3 addTarget:self action:@selector(textFieldChange:) forControlEvents:UIControlEventEditingChanged];
    }
    return _pwTf3;
}
   /** 确认修改*/
-(UIButton *)sureBtn{
    if (_sureBtn==nil) {
     
        _sureBtn                     = [[UIButton alloc] init];
        [_sureBtn setTitle:@"确认修改" forState:UIControlStateNormal];
        [_sureBtn setTitleColor:[UIColor colorWithWhite:0.304 alpha:1.000] forState:UIControlStateNormal];
      
        [_sureBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
        [_sureBtn setBackgroundColor:[UIColor colorWithRed:(188/255.0) green:(188/255.0) blue:(188/255.0) alpha:1]];
        _sureBtn.layer.cornerRadius  = 5;
        _sureBtn.layer.masksToBounds = YES;
        _sureBtn.enabled             = NO;
       
    }
    return _sureBtn;
}
-(UILabel *)lable{
    if (_lable==nil) {
        _lable =[[UILabel alloc]init];
        _lable.text     = @"请您最少输入6个字符";
        _lable.font     = [UIFont systemFontOfSize:13];
        
        
    }
    return _lable;
    
}
#pragma mark 布局
- (void)layoutViews {
    _backView.sd_layout
    .topSpaceToView(self,84)
    .leftSpaceToView(self,10)
    .rightSpaceToView(self,10)
    .heightIs(40);
    
    _typeLbl.sd_layout
    .topEqualToView(_backView)
    .leftSpaceToView(_backView,10)
    .widthIs(110)
    .bottomEqualToView(_backView);
    
    _pwTf.sd_layout
    .topEqualToView(_backView)
    .leftSpaceToView(_typeLbl,0)
    .rightEqualToView(_backView)
    .bottomEqualToView(_backView);
    
    // 新密码
    _backView2.sd_layout
    .topSpaceToView(_backView,15)
    .leftSpaceToView(self,10)
    .rightSpaceToView(self,10)
    .heightIs(40);
    
    _typeLbl2.sd_layout
    .topEqualToView(_backView2)
    .leftSpaceToView(_backView2,10)
    .widthIs(110)
    .bottomEqualToView(_backView2);
    
    _pwTf2.sd_layout
    .topEqualToView(_backView2)
    .leftSpaceToView(_typeLbl2,0)
    .rightEqualToView(_backView2)
    .bottomEqualToView(_backView2);
    
    // 确定新密码
    _backView3.sd_layout
    .topSpaceToView(_backView2,15)
    .leftSpaceToView(self,10)
    .rightSpaceToView(self,10)
    .heightIs(40);
    
    
    _typeLbl3.sd_layout
    .topEqualToView(_backView3)
    .leftSpaceToView(_backView3,10)
    .widthIs(110)
    .bottomEqualToView(_backView3);
    
    _pwTf3.sd_layout
    .topEqualToView(_backView3)
    .leftSpaceToView(_typeLbl3,0)
    .rightEqualToView(_backView3)
    .bottomEqualToView(_backView3);
    
    // 确认修改
    _sureBtn.sd_layout
    .topSpaceToView(_backView3,30)
    .leftSpaceToView(self,10)
    .rightSpaceToView(self,10)
    .heightIs(40);
    
    _lable.sd_layout
    .topSpaceToView(_sureBtn,3)
    .leftEqualToView(_sureBtn)
    .rightEqualToView(_sureBtn)
    .heightIs(40);
    
}


// 开始编辑
- (BOOL) textFieldShouldBeginEditing:(UITextField*) textField {
    switch (textField.tag) {
            
        case 1:
            _backView.layer.borderColor = [UIColor colorWithRed:(233/255.0) green:(109/255.0) blue:(7/255.0) alpha:1].CGColor;
            _backView2.layer.borderColor = [UIColor colorWithRed:(192/255.0) green:(192/255.0) blue:(192/255.0) alpha:1].CGColor;
            _backView3.layer.borderColor = [UIColor colorWithRed:(192/255.0) green:(192/255.0) blue:(192/255.0) alpha:1].CGColor;
            break;
            
        case 2:
            _backView.layer.borderColor = [UIColor colorWithRed:(192/255.0) green:(192/255.0) blue:(192/255.0) alpha:1].CGColor;
            _backView2.layer.borderColor = [UIColor colorWithRed:(233/255.0) green:(109/255.0) blue:(7/255.0) alpha:1].CGColor;
            _backView3.layer.borderColor = [UIColor colorWithRed:(192/255.0) green:(192/255.0) blue:(192/255.0) alpha:1].CGColor;
            
            break;
            
        case 3:
            _backView.layer.borderColor = [UIColor colorWithRed:(192/255.0) green:(192/255.0) blue:(192/255.0) alpha:1].CGColor;
            _backView2.layer.borderColor = [UIColor colorWithRed:(192/255.0) green:(192/255.0) blue:(192/255.0) alpha:1].CGColor;
            _backView3.layer.borderColor = [UIColor colorWithRed:(233/255.0) green:(109/255.0) blue:(7/255.0) alpha:1].CGColor;
            
            break;
            
        default:
            break;
    }
    return YES;
}

//收回键盘
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    [self endEditing:YES];
}

- (void)textFieldChange:(UITextField *)sender {
    
    static BOOL tfOne   = false;
    static BOOL tfTwo   = false;
    static BOOL tfThree = false;
    
    switch (sender.tag) {
            
        case 1:
            if (sender.text.length > 0) {
                tfOne   = true;
            } else {
                tfOne   = false;
            }
            break;
            
        case 2:
            if (sender.text.length > 5) {
                tfTwo   = true;
            } else {
                tfTwo   = false;
            }
            break;
            
        case 3:
            if (sender.text.length > 5) {
                tfThree   = true;
            } else {
                tfThree   = false;
            }
            
            break;
            
        default:
            break;
    }
    
    if (tfOne == true && tfTwo == true && tfThree == true) {
        _sureBtn.backgroundColor = [UIColor colorWithRed:(233/255.0) green:(109/255.0) blue:(7/255.0) alpha:1];
        [_sureBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _sureBtn.enabled         = YES;
    } else {
        [_sureBtn setBackgroundColor:[UIColor colorWithRed:(188/255.0) green:(188/255.0) blue:(188/255.0) alpha:1]];
        [_sureBtn setTitleColor:[UIColor colorWithRed:(85/255.0) green:(85/255.0) blue:(85/255.0) alpha:1] forState:UIControlStateNormal];
        _sureBtn.enabled         = NO;
    }
}
@end
